//
//  ELMainTabBarController.swift
//  SinaWeiBo
//
//  Created by jiwang on 15/12/15.
//  Copyright © 2015年 jiwang. All rights reserved.
//

import UIKit

class ELMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

//        tabBar.tintColor = UIColor .orangeColor()
        
        //自定义tabBar
        let tabbar = ELCostomTabBar()
        setValue(tabbar, forKey: "tabBar")
        
        setupSubController(ELHomeViewController(), titleName: "主页", imageName: "tabbar_home")
        setupSubController(ELMessageViewController(), titleName: "消息", imageName: "tabbar_message_center")
        setupSubController(ELDiscoverViewController(), titleName: "发现", imageName: "tabbar_discover")
        setupSubController(ELProfileViewController(), titleName: "个人", imageName: "tabbar_profile")
        
    }
    
    func setupSubController (subCV :UIViewController , titleName : String , imageName : String) {
        //设置标题,全局的，包括nav 和tabbar
        subCV.title = titleName
        //设置图片
        subCV.tabBarItem.image = UIImage(named:imageName)
        subCV.tabBarItem.selectedImage = UIImage(named: "\(imageName)_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置字体属性
        subCV.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor .orangeColor()], forState: UIControlState.Selected)
        
        let nav = UINavigationController()
        //设置全局navigationBar样式
        let navBar = UINavigationBar.appearance()
        navBar.tintColor = UIColor.orangeColor()
        
        nav.addChildViewController(subCV)
        addChildViewController(nav)
    }
}
